home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.misc
- From: brad@hcx1.ssd.csd.harris.com (Brad Appleton)
- Subject: v26i116: parseargs - functions to parse command line arguments, Patch10
- Message-ID: <1991Dec22.205629.22580@sparky.imd.sterling.com>
- X-Md4-Signature: 0f0501ceec759861f89d8fc11a62c655
- Date: Sun, 22 Dec 1991 20:56:29 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: brad@hcx1.ssd.csd.harris.com (Brad Appleton)
- Posting-number: Volume 26, Issue 116
- Archive-name: parseargs/patch10
- Environment: UNIX, VMS, MS-DOS, OS/2, Amiga
- Patch-To: parseargs: Volume 17, Issue 46-57
-
- This is patch10 of parseargs. It fixes some bugs introduced by (a poorly
- tested) patchlevel 9 and adds one new enhancement (the optional use of
- '--' instead of '+' as the unix long option prefix).
-
- To install this patch:
-
- 1) cd to your parseargs directory and unshar this file to create PATCH10
-
- 2) type "patch -p0 <PATCH10"
-
- ______________________ "And miles to go before I sleep." ______________________
- Brad Appleton Harris Corp., Computer Systems Division
- Software Engineer 2101 West Cypress Creek Road, M/S 161
- brad@ssd.csd.harris.com Fort Lauderdale, FL 33309-1892 USA
- ...!uunet!travis!brad Phone: (305) 973-5190
- ~~~~~~~~~~~~~~~~~~~~ Disclaimer: I said it, not my company! ~~~~~~~~~~~~~~~~~~~
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of shell archive."
- # Contents: PATCH10
- # Wrapped by brad@hcx1 on Thu Dec 5 10:15:52 1991
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'PATCH10' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'PATCH10'\"
- else
- echo shar: Extracting \"'PATCH10'\" \(15747 characters\)
- sed "s/^X//" >'PATCH10' <<'END_OF_FILE'
- X*** MANIFEST.OLD Thu Dec 5 09:54:30 1991
- X--- MANIFEST Tue Nov 26 16:39:21 1991
- X***************
- X*** 47,53 ****
- X parseargs.c 8 C source for parseargs(1)
- X parseargs.h 7 include file for parseargs library
- X parseargs.pl 2 parseargs for perl
- X! patchlevel.h 2 list of patches (most recent first)
- X pgopen.c 4 pipe output to a pager
- X pgopen.h 1 include file for pgopen.c
- X stest.c 4 test program for parseargs(3)
- X--- 47,53 ----
- X parseargs.c 8 C source for parseargs(1)
- X parseargs.h 7 include file for parseargs library
- X parseargs.pl 2 parseargs for perl
- X! patchlevel.h 3 list of patches (most recent first)
- X pgopen.c 4 pipe output to a pager
- X pgopen.h 1 include file for pgopen.c
- X stest.c 4 test program for parseargs(3)
- X***************
- X*** 62,68 ****
- X test.sh 1 Bourne shell test program for parseargs(1)
- X test.zsh 2 Z shell test program for parseargs(1)
- X unix_args.c 5 parse Unix command-lines
- X! unix_man.c 3 print Unix manual-page templates
- X useful.h 3 common include file for the library
- X vms_args.c 6 parse VAX/VMS DCL command-lines
- X vprintf.c 3 portable vfprintf, vprintf, and vsprintf
- X--- 62,68 ----
- X test.sh 1 Bourne shell test program for parseargs(1)
- X test.zsh 2 Z shell test program for parseargs(1)
- X unix_args.c 5 parse Unix command-lines
- X! unix_man.c 4 print Unix manual-page templates
- X useful.h 3 common include file for the library
- X vms_args.c 6 parse VAX/VMS DCL command-lines
- X vprintf.c 3 portable vfprintf, vprintf, and vsprintf
- X*** README.OLD Thu Dec 5 09:54:39 1991
- X--- README Thu Dec 5 09:54:03 1991
- X***************
- X*** 628,633 ****
- X--- 628,636 ----
- X I also provided extensive updating to the manual pages so that they
- X now reflect the current capabilities of parseargs!
- X
- X+ Since the FSF has decided to change the use of '+' as a long-option prefix
- X+ to '--' (in order to be POSIX conformant), I added some #ifdef POSIX_SOURCE
- X+ code to unix_args.c to use '--' instead of '+' as the long option prefix.
- X
- X MODIFICATIONS TO parseargs.h
- X ============================
- X***************
- X*** 770,776 ****
- X If any of the following macros are #defined at compile time then they will
- X have the following effect:
- X
- X! USE_PAGER -- for Unix systems only. Parseargs will include the code
- X which pipes usage messages to a paging program
- X
- X NOFLOAT -- Parseargs will NOT include the code for the predefined
- X--- 773,779 ----
- X If any of the following macros are #defined at compile time then they will
- X have the following effect:
- X
- X! USE_PAGER -- For Unix systems only. Parseargs will include the code
- X which pipes usage messages to a paging program
- X
- X NOFLOAT -- Parseargs will NOT include the code for the predefined
- X***************
- X*** 783,788 ****
- X--- 786,794 ----
- X USE_TERMINFO
- X USE_TERMCAP -- Parseargs will use curses/terminfo/termcap when trying
- X to figure out the size of the screen.
- X+
- X+ POSIX_SOURCE -- For unix_style only. Parseargs will use '--' instead of
- X+ '+' as the long-option prefix.
- X
- X IBM-PC VERSION OF parseargs(3)
- X ==============================
- X*** amiga_args.c.OLD Thu Dec 5 09:54:49 1991
- X--- amiga_args.c Tue Nov 26 16:31:18 1991
- X***************
- X*** 518,524 ****
- X
- X if ( description && *description ) {
- X fprintf( fp, "Description:\n" );
- X! indent_para(fp, max_cols, 8, "", 0, description);
- X fputc( '\n', fp );
- X }
- X }/*if*/
- X--- 518,524 ----
- X
- X if ( description && *description ) {
- X fprintf( fp, "Description:\n" );
- X! indent_para(fp, max_cols, 8, "", 0, description, 0);
- X fputc( '\n', fp );
- X }
- X }/*if*/
- X*** doc/parseargs.man3.OLD Thu Dec 5 09:55:16 1991
- X--- doc/parseargs.man3 Thu Dec 5 09:41:33 1991
- X***************
- X*** 197,203 ****
- X Under \s-1UNIX\s+1, \s-1MS-DOS\s+1, and \s-1OS\s+1/2,
- X \fIparseargs\fP also allows for long
- X options in addition to single character options.
- X! Under \s-1UNIX\s+1, long options are denoted by a `\fB+\fP' character.
- X Under \s-1MS-DOS\s+1, and \s-1OS\s+1/2, long options are denoted by the second
- X character in the \s-1SWITCHAR\s+1 environment variable. If there is no second
- X character, then if the first character is `\-', then a `\fB+\fP' is used,
- X--- 197,205 ----
- X Under \s-1UNIX\s+1, \s-1MS-DOS\s+1, and \s-1OS\s+1/2,
- X \fIparseargs\fP also allows for long
- X options in addition to single character options.
- X! Under \s-1UNIX\s+1, long options are denoted by a `\fB+\fP' character
- X! (unless \fIparseargs\fP was compiled for conformance with POSIX, inc which
- X! case the long option prefix is `\fB\-\|\-\fP').
- X Under \s-1MS-DOS\s+1, and \s-1OS\s+1/2, long options are denoted by the second
- X character in the \s-1SWITCHAR\s+1 environment variable. If there is no second
- X character, then if the first character is `\-', then a `\fB+\fP' is used,
- X*** ibm_args.c.OLD Thu Dec 5 09:55:31 1991
- X--- ibm_args.c Tue Nov 26 16:31:27 1991
- X***************
- X*** 764,770 ****
- X
- X if ( description && *description ) {
- X fprintf( fp, "Description:\n" );
- X! indent_para(fp, max_cols, 8, "", 0, description);
- X fputc( '\n', fp );
- X }
- X }/*if*/
- X--- 764,770 ----
- X
- X if ( description && *description ) {
- X fprintf( fp, "Description:\n" );
- X! indent_para(fp, max_cols, 8, "", 0, description, 0);
- X fputc( '\n', fp );
- X }
- X }/*if*/
- X*** patchlevel.h.OLD Thu Dec 5 09:55:41 1991
- X--- patchlevel.h Thu Dec 5 09:10:23 1991
- X***************
- X*** 2,7 ****
- X--- 2,17 ----
- X ** ^FILE: patchlevel.h - current patchlevel for parseargs
- X **
- X ** ^HISTORY:
- X+ ** 12/05/91 Brad Appleton <brad@ssd.csd.harris.com>
- X+ ** Patch10
- X+ ** - Fix bug that was introduced in last patch. Pgopen() was not
- X+ ** using $USAGE_PAGER, it was only using $PAGER.
- X+ ** - When Earl added the extra argument to indent_para(), he forgot to
- X+ ** include the argument when printing the command description. I added
- X+ ** this into *_args.c
- X+ ** - Added #ifdef POSIX_SOURCE stuff to unix_args.c to allow the use
- X+ ** of '--' instead of '+' as the long option prefix.
- X+ **
- X ** 08/27/91 Brad Appleton <brad@ssd.csd.harris.com>
- X ** 08/27/91 Earl Chew <cechew@bruce.cs.monash.edu.au>
- X ** Patch09
- X***************
- X*** 19,25 ****
- X ** at odds with the documentation and requires (int *) on reads.
- X ** Also, should check for NULL cmd-name before passing it to strdup().
- X ** - vms_args.c/is_cmdline():
- X! ** Mike Level pointed out to me that if lib$get_foreing returns a
- X ** zero-length string then the proper actions are not taken. This
- X ** has been fixed.
- X ** - vms_args.c, parseargs.h, xparse.c
- X--- 29,35 ----
- X ** at odds with the documentation and requires (int *) on reads.
- X ** Also, should check for NULL cmd-name before passing it to strdup().
- X ** - vms_args.c/is_cmdline():
- X! ** Mike Levin pointed out to me that if lib$get_foreign returns a
- X ** zero-length string then the proper actions are not taken. This
- X ** has been fixed.
- X ** - vms_args.c, parseargs.h, xparse.c
- X***************
- X*** 132,138 ****
- X
- X #define VERSION 2
- X #define REVISION 0
- X! #define PATCHLEVEL 9
- X
- X #ifdef __STDC__
- X static const char
- X--- 142,148 ----
- X
- X #define VERSION 2
- X #define REVISION 0
- X! #define PATCHLEVEL 10
- X
- X #ifdef __STDC__
- X static const char
- X***************
- X*** 139,142 ****
- X #else
- X static char
- X #endif
- X! _Ident[] = "@(#)parseargs 2.0 patchlevel 9";
- X--- 149,152 ----
- X #else
- X static char
- X #endif
- X! _Ident[] = "@(#)parseargs 2.0 patchlevel 10";
- X*** pgopen.c.OLD Thu Dec 5 09:55:48 1991
- X--- pgopen.c Wed Nov 27 11:07:35 1991
- X***************
- X*** 32,38 ****
- X #include <useful.h>
- X
- X /* get #defines for access() call */
- X! #include <sys/file.h>
- X #ifndef X_OK
- X # define X_OK 0x01
- X #endif
- X--- 32,40 ----
- X #include <useful.h>
- X
- X /* get #defines for access() call */
- X! #ifndef SYSV
- X! # include <sys/file.h>
- X! #endif
- X #ifndef X_OK
- X # define X_OK 0x01
- X #endif
- X***************
- X*** 418,424 ****
- X if ( Pager_Type != PG_NONE ) pg_type = Pager_Type;
- X
- X /* see if the given pager is okay */
- X! if ( !pg_name || !*pg_name || !access(pg_name, X_OK) ) {
- X pg_name = getenv("PAGER");
- X }
- X else {
- X--- 420,426 ----
- X if ( Pager_Type != PG_NONE ) pg_type = Pager_Type;
- X
- X /* see if the given pager is okay */
- X! if ( !pg_name || !*pg_name || access(pg_name, X_OK) ) {
- X pg_name = getenv("PAGER");
- X }
- X else {
- X*** strfuncs.c.OLD Thu Dec 5 09:56:00 1991
- X--- strfuncs.c Wed Nov 27 11:08:42 1991
- X***************
- X*** 32,43 ****
- X ** indent_para() -- print an indented hanging paragraph
- X **
- X ** ^HISTORY:
- X ** 08/27/91 Earl Chew <cechew@bruce.cs.monash.edu.au>
- X ** - add extra length argument to indent_para().
- X ** - add FORCE_KWDCASE() macro
- X ** - add non-writable strings support to get_argname() and
- X ** get_kwdname()
- X- ** 08/27/91 Earl Chew <cechew@bruce.cs.monash.edu.au>
- X ** - add get_argpfx() and get_argdesc() for non-writable strings
- X ** support
- X ** - allow zero length string for strsplit()
- X--- 32,47 ----
- X ** indent_para() -- print an indented hanging paragraph
- X **
- X ** ^HISTORY:
- X+ **
- X+ ** 11/26/91 Brad Appleton <brad@ssd.csd.harris.com>
- X+ ** - added the following to indent_para(). If last arg is 0,
- X+ ** then the whole length is used.
- X+ **
- X ** 08/27/91 Earl Chew <cechew@bruce.cs.monash.edu.au>
- X ** - add extra length argument to indent_para().
- X ** - add FORCE_KWDCASE() macro
- X ** - add non-writable strings support to get_argname() and
- X ** get_kwdname()
- X ** - add get_argpfx() and get_argdesc() for non-writable strings
- X ** support
- X ** - allow zero length string for strsplit()
- X***************
- X*** 650,660 ****
- X do {
- X *pwrite++ = c;
- X } while ( (c = *pread++) && !strchr(separators, c) );
- X- *pwrite++ = '\0';
- X- ++count;
- X- do {
- X- *pwrite++ = c;
- X- } while ( (c = *pread++) && !strchr(separators, c) );
- X *pwrite++ = '\0';
- X ++count;
- X }/*if*/
- X--- 654,659 ----
- X***************
- X*** 1370,1375 ****
- X--- 1369,1376 ----
- X register int idx = 0;
- X BOOL first_line = TRUE;
- X char ch;
- X+
- X+ if ( ! textlen ) textlen = strlen( text );
- X
- X /* print the title */
- X fprintf( fp, "%*s%-*s", margin, "", indent, title );
- X*** unix_args.c.OLD Thu Dec 5 09:56:18 1991
- X--- unix_args.c Thu Dec 5 09:21:48 1991
- X***************
- X*** 6,12 ****
- X ** vectors and to print Unix usage messages.
- X **
- X ** ^HISTORY:
- X! ** 27/08/91 Earl Chew <cechew@bruce.cs.monash.edu.au>
- X ** - Use ProgNameLen when accessing ProgName
- X ** - Use get_argdesc() to access description
- X **
- X--- 6,16 ----
- X ** vectors and to print Unix usage messages.
- X **
- X ** ^HISTORY:
- X! ** 12/05/91 Brad Appleton <brad@ssd.csd.harris.com>
- X! ** - added #ifdef POSIX_SOURCE to use "--" instead of "+" as
- X! ** GNU conformant prefix for long options.
- X! **
- X! ** 08/27/91 Earl Chew <cechew@bruce.cs.monash.edu.au>
- X ** - Use ProgNameLen when accessing ProgName
- X ** - Use get_argdesc() to access description
- X **
- X***************
- X*** 54,67 ****
- X #define isOPT(s) \
- X ( !BTEST(cmd_flags(cmd), pa_KWDSONLY) && \
- X !BTEST(cmd_state(cmd), ps_NOFLAGS) && \
- X! *s == c_OPT_PFX && *(s+1) \
- X )
- X
- X #define isKWD(s) \
- X ( !BTEST(cmd_flags(cmd), pa_OPTSONLY) && \
- X !BTEST(cmd_state(cmd), ps_NOFLAGS) && \
- X! *s == c_KWD_PFX && *(s+1) \
- X )
- X
- X
- X /***************************************************************************
- X--- 58,79 ----
- X #define isOPT(s) \
- X ( !BTEST(cmd_flags(cmd), pa_KWDSONLY) && \
- X !BTEST(cmd_state(cmd), ps_NOFLAGS) && \
- X! (*s == c_OPT_PFX) && *(s+1) \
- X )
- X
- X+ #ifndef POSIX_SOURCE
- X #define isKWD(s) \
- X ( !BTEST(cmd_flags(cmd), pa_OPTSONLY) && \
- X !BTEST(cmd_state(cmd), ps_NOFLAGS) && \
- X! (*s == c_KWD_PFX) && *(s+1) \
- X )
- X+ #else
- X+ #define isKWD(s) \
- X+ ( !BTEST(cmd_flags(cmd), pa_OPTSONLY) && \
- X+ !BTEST(cmd_state(cmd), ps_NOFLAGS) && \
- X+ (*s == c_OPT_PFX) && (*(s+1) == c_OPT_PFX) && *(s+2) \
- X+ )
- X+ #endif
- X
- X
- X /***************************************************************************
- X***************
- X*** 135,140 ****
- X--- 147,153 ----
- X if ( isKWD(p) ) { /* we have a keyword here */
- X char *s, c = '\0';
- X
- X+ #ifndef POSIX_SOURCE
- X /* check for `++' to end flags */
- X if ( *(p+1) == c_KWD_PFX && !*(p+2) ) {
- X BSET( cmd_state(cmd), ps_NOFLAGS );
- X***************
- X*** 141,148 ****
- X--- 154,165 ----
- X cmd_list(cmd) = ARGDESCNULL;
- X continue;
- X }
- X+ #endif
- X
- X /* get past prefix and look for possible argument */
- X+ #ifdef POSIX_SOURCE
- X+ ++p;
- X+ #endif
- X s = strpbrk(++p, s_ARG_SEP);
- X if(s) {
- X c = *s;
- X***************
- X*** 164,170 ****
- X--- 181,191 ----
- X if ( c ) *(s-1) = c; /* restore the equal sign */
- X
- X if ( !is_match ) {
- X+ #ifndef POSIX_SOURCE
- X usrerr("option %c%s unknown", c_KWD_PFX, p);
- X+ #else
- X+ usrerr("option %c%c%s unknown", c_OPT_PFX, c_OPT_PFX, p);
- X+ #endif
- X parse_error = pe_SYNTAX;
- X cmd_list(cmd) = ARGDESCNULL;
- X continue;
- X***************
- X*** 525,535 ****
- X--- 546,565 ----
- X sprintf( buf, "%c%c", c_OPT_PFX, arg_cname(ad) );
- X }
- X else if ( !(usgflags & usg_OPTS) ) {
- X+ #ifndef POSIX_SOURCE
- X sprintf( buf, "%c%s", c_KWD_PFX, keyword );
- X+ #else
- X+ sprintf( buf, "%c%c%s", c_OPT_PFX, c_OPT_PFX, keyword );
- X+ #endif
- X }
- X else { /* use both */
- X+ #ifndef POSIX_SOURCE
- X sprintf( buf, "%c%c|%c%s", c_OPT_PFX, arg_cname(ad),
- X c_KWD_PFX, keyword );
- X+ #else
- X+ sprintf( buf, "%c%c|%c%c%s", c_OPT_PFX, arg_cname(ad),
- X+ c_OPT_PFX, c_OPT_PFX, keyword );
- X+ #endif
- X }
- X
- X pos = buf + strlen(buf);
- X***************
- X*** 680,686 ****
- X
- X if ( description && *description ) {
- X fprintf( fp, "Description:\n" );
- X! indent_para(fp, max_cols, 8, "", 0, description);
- X fputc( '\n', fp );
- X }
- X }/*if*/
- X--- 710,716 ----
- X
- X if ( description && *description ) {
- X fprintf( fp, "Description:\n" );
- X! indent_para(fp, max_cols, 8, "", 0, description, 0);
- X fputc( '\n', fp );
- X }
- X }/*if*/
- X*** vms_args.c.OLD Thu Dec 5 09:56:28 1991
- X--- vms_args.c Tue Nov 26 16:35:15 1991
- X***************
- X*** 1027,1033 ****
- X
- X if ( description && *description ) {
- X fprintf( fp, "Description:\n" );
- X! indent_para(fp, max_cols, 8, "", 0, description);
- X fputc( '\n', fp );
- X }
- X }/*if*/
- X--- 1027,1033 ----
- X
- X if ( description && *description ) {
- X fprintf( fp, "Description:\n" );
- X! indent_para(fp, max_cols, 8, "", 0, description, 0);
- X fputc( '\n', fp );
- X }
- X }/*if*/
- END_OF_FILE
- if test 15747 -ne `wc -c <'PATCH10'`; then
- echo shar: \"'PATCH10'\" unpacked with wrong size!
- fi
- # end of 'PATCH10'
- fi
- echo shar: End of shell archive.
- exit 0
-
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-